from django.db import models


# Create your models here.
class Purpose(models.Model):
    pname = models.CharField(max_length=50)
    class Meta:
        db_table = 'purpose'
    def __str__(self):
        return self.pname
class Flower(models.Model):
    name = models.CharField(max_length=50)
    purpose = models.ForeignKey(Purpose, on_delete=models.CASCADE)
    price= models.DecimalField(max_digits=5, decimal_places=2)
    color = models.CharField(max_length=50)
    img= models.ImageField(upload_to='uploads/flower',default="")
    desc= models.TextField()
    class Meta:
        db_table = 'flower'
    def __str__(self):
        return self.name

class MyCart(models.Model):
    flower = models.ForeignKey(Flower, on_delete=models.CASCADE)
    user=models.IntegerField(default=1)
    number=models.IntegerField(default=1)
    select=models.BooleanField(default=True)
    class Meta:
        db_table = 'mycart'

class  MyOrder(models.Model):
    user=models.IntegerField(default=1)
    order_time=models.DateTimeField(auto_now_add=True)
    total=models.DecimalField(max_digits=5, decimal_places=2)
    status=models.IntegerField(default=0,choices=((0,'未支付'),(1,'已支付'),(2,'已完成')))
    orderno=models.CharField(max_length=50)
    payno=models.CharField(max_length=50,null=True,blank=True)
    paytime=models.DateTimeField(null=True,blank=True)
    class Meta:
        db_table = 'myorder'
    def __str__(self):
        return self.orderno
class MyDetail(models.Model):
    order=models.ForeignKey(MyOrder, on_delete=models.CASCADE)
    flower=models.ForeignKey(Flower, on_delete=models.CASCADE)
    number=models.IntegerField(default=1)
    price=models.DecimalField(max_digits=5, decimal_places=2)
    img=models.CharField(max_length=200)
    class Meta:
        db_table = 'mydetail'
